﻿Imports DevExpress.XtraVerticalGrid

''' <summary>
''' @NAMNN
''' Tạo grid lọc hiệu quả,bỏ button edit filter 
''' </summary>
''' <remarks></remarks>
Public Class VmsGridView
    Inherits DevExpress.XtraGrid.Views.Grid.GridView
    Private setFilter As Boolean = False
    'Tạo delegate 
    Public Delegate Sub SuKien(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
    ' Public CallEventRefesh, CallEventAdd, CallEventEdit, CallEventDelete, CallEventInfo, CallEventPrint As SuKien
    
    Public Overrides Sub Focus()
        If Not setFilter Then
            MyBase.Focus()
            MyBase.ApplyColumnsFilter()           
            For Each item As DevExpress.XtraGrid.Columns.GridColumn In Me.Columns
                item.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains
            Next
            setFilter = True
        End If
    End Sub

    Public Overloads Sub Shadow(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Try
            If Me.FocusedRowHandle = 0 AndAlso e.KeyCode = Windows.Forms.Keys.Up Then
                Me.FocusedRowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle
            End If
            If e.KeyCode = Windows.Forms.Keys.Home Then
                Me.FocusedRowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle
            End If 
            If e.Control AndAlso e.KeyCode = Windows.Forms.Keys.C Then
                e.Handled = SetClipboardValueCellFocusInGrid(Me)
            End If
            'Xuất dữ liệu 
            'If (e.Modifiers = GetKeyModifide(pIdXuat) And _
            '         e.KeyCode = GetKeyCode(pIdXuat)) Or _
            '         (e.KeyCode = GetKeyCode(pIdXuat)) Then
            '    Dim Save As New System.Windows.Forms.SaveFileDialog
            '    Export_Dialog(Save, Me.GridControl, "xls")
            'End If
            ''Them mới
            'If (e.Modifiers = GetKeyModifide("ADD") And _
            '   e.KeyCode = GetKeyCode("ADD")) Or _
            '   (e.KeyCode = GetKeyCode("ADD")) Then
            '    If CallEventAdd IsNot Nothing Then CallEventAdd(Me, Nothing)
            'End If
            ''sửa 
            'If (e.Modifiers = GetKeyModifide("EDIT") And _
            '   e.KeyCode = GetKeyCode("EDIT")) Or _
            '   (e.KeyCode = GetKeyCode("EDIT")) Then
            '    If CallEventEdit IsNot Nothing Then CallEventEdit(Nothing, Nothing)
            'End If
            ' ''Xóa
            'If (e.Modifiers = GetKeyModifide("DELETE") And _
            'e.KeyCode = GetKeyCode("DELETE")) Or _
            '(e.KeyCode = GetKeyCode("DELETE")) Then
            '    If CallEventDelete IsNot Nothing Then CallEventDelete(Nothing, Nothing)
            'End If
            ''Thoát			
            ''If (e.Modifiers = GetKeyModifide("EXIT") And _
            ''    e.KeyCode = GetKeyCode("EXIT")) Or _
            ''    (e.KeyCode = GetKeyCode("EXIT")) Then
            ''    If CallEventExit IsNot Nothing Then CallEventExit(Nothing, Nothing)
            ''End If
            ''Thông tin 
            ''Thoát			
            'If (e.Modifiers = GetKeyModifide("INFO") And _
            '    e.KeyCode = GetKeyCode("INFO")) Or _
            '    (e.KeyCode = GetKeyCode("INFO")) Then
            '    If CallEventInfo IsNot Nothing Then CallEventInfo(Nothing, Nothing)
            'End If
            'If (e.Modifiers = GetKeyModifide("PRINT") And _
            '   e.KeyCode = GetKeyCode("PRINT")) Or _
            '   (e.KeyCode = GetKeyCode("PRINT")) Then
            '    If CallEventPrint IsNot Nothing Then CallEventPrint(Nothing, Nothing)
            'End If
            'If (e.Modifiers = GetKeyModifide("REFRESH") And _
            '  e.KeyCode = GetKeyCode("REFRESH")) Or _
            '  (e.KeyCode = GetKeyCode("REFRESH")) Then
            '    If CallEventRefesh IsNot Nothing Then CallEventRefesh(Nothing, Nothing)
            'End If

        Catch ex As Exception
            MsgInfo(ex.Message)
        End Try
    End Sub

    Protected Overrides ReadOnly Property ViewName() As String
        Get
            Return MyBase.ViewName
        End Get
    End Property

    Private Sub InitializeComponent()
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'VmsGridView
        '
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Private Sub VmsGridView_ShowGridMenu(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs) Handles Me.ShowGridMenu
        ShowGridMenuText(e)
    End Sub
     
End Class
